Spot-On
spot-on-smp.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef _spoton_smp_h_
29 #define _spoton_smp_h_
30 
31 #include <QByteArray>
32 #include <QList>
33 #include <QString>
34 
35 extern "C"
36 {
37 #include <gcrypt.h>
38 }
39 
41 {
42  public:
43  spoton_smp(void);
44  ~spoton_smp(void);
45  static const unsigned int BITS = 1536;
46  static gcry_mpi_t generateWeakRandomPrime(bool *ok);
47  static void test1(void);
48  static void test2(void);
49  static void test3(void);
50  static void test4(void);
51  QByteArray guessSha(void) const;
52  QByteArray guessWhirlpool(void) const;
53  QList<QByteArray> coordinatesProof(const gcry_mpi_t g2,
54  const gcry_mpi_t g3,
55  const gcry_mpi_t r,
56  const int version,
57  bool *ok) const;
58  QList<QByteArray> equalLogs(const gcry_mpi_t qab,
59  const gcry_mpi_t x,
60  const int version,
61  bool *ok) const;
62  QList<QByteArray> logProof(const gcry_mpi_t g,
63  const gcry_mpi_t x,
64  const int version,
65  bool *ok) const;
66  QList<QByteArray> nextStep(const QList<QByteArray> &other,
67  bool *ok, bool *passed);
68  QList<QByteArray> step1(bool *ok);
69 
70  QString guessString(void) const
71  {
72  return m_guessString;
73  }
74 
75  bool passed(void) const;
76  bool verifyCoordinatesProof(const QList<QByteArray> &list,
77  const gcry_mpi_t g2,
78  const gcry_mpi_t g3,
79  const gcry_mpi_t p,
80  const gcry_mpi_t q,
81  const int version) const;
82  bool verifyEqualLogs(const QList<QByteArray> &list,
83  const gcry_mpi_t g3,
84  const gcry_mpi_t qab,
85  const gcry_mpi_t r,
86  const int version) const;
87  bool verifyLogProof(const QList<QByteArray> &list,
88  const gcry_mpi_t g,
89  const gcry_mpi_t x,
90  const int version) const;
91  int step(void) const;
92  void initialize();
93  void setGuess(const QString &guess);
94 
95  void setModulus(const gcry_mpi_t modulus)
96  {
97  gcry_mpi_release(m_modulus);
98  m_modulus = gcry_mpi_copy(modulus);
99  }
100 
101  void setStep0(void)
102  {
103  m_step = 0;
104  }
105 
106  private:
107  QString m_guessString;
108  bool m_passed;
109  char *m_guessWhirl; // Stored in secure memory.
110  gcry_mpi_t m_a2;
111  gcry_mpi_t m_a3;
112  gcry_mpi_t m_b2;
113  gcry_mpi_t m_b3;
114  gcry_mpi_t m_g2b;
115  gcry_mpi_t m_g3a;
116  gcry_mpi_t m_g3b;
117  gcry_mpi_t m_generator;
118  gcry_mpi_t m_guess;
119  gcry_mpi_t m_modulus;
120  gcry_mpi_t m_order;
121  gcry_mpi_t m_pa;
122  gcry_mpi_t m_pb;
123  gcry_mpi_t m_qab;
124  gcry_mpi_t m_qb;
125  gcry_mpi_t generateRandomExponent(bool *ok) const;
126  int m_step;
127  size_t m_guessWhirlLength;
128  static const int TERMINAL_STATE = -1;
129  QList<QByteArray> step2(const QList<QByteArray> &other, bool *ok);
130  QList<QByteArray> step3(const QList<QByteArray> &other, bool *ok);
131  QList<QByteArray> step4(const QList<QByteArray> &other,
132  bool *ok,
133  bool *passed);
134  void reset(void);
135  void step5(const QList<QByteArray> &other, bool *ok, bool *passed);
136 };
137 
138 #endif
Definition: spot-on-smp.h:40